home *** CD-ROM | disk | FTP | other *** search
/ PC World 2008 February (DVD) / PCWorld_2008-02_DVD.iso / v cisle / PHP / PHP.exe / xampp-win32-1.6.5-installer.exe / phpMyAdmin / libraries / auth / cookie.auth.lib.php < prev    next >
Encoding:
PHP Script  |  2007-12-20  |  19.8 KB  |  604 lines

  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4.  * Set of functions used to run cookie based authentication.
  5.  * Thanks to Piotr Roszatycki <d3xter at users.sourceforge.net> and
  6.  * Dan Wilson who built this patch for the Debian package.
  7.  *
  8.  * @version $Id: cookie.auth.lib.php 10931 2007-11-20 12:55:14Z lem9 $
  9.  */
  10.  
  11. /**
  12.  * @todo replace by constant
  13.  * $coming_from_common can be set from outside with register_globals on
  14.  */
  15. if (!isset($coming_from_common)) {
  16.    exit;
  17. }
  18.  
  19. if (function_exists('mcrypt_encrypt') || PMA_dl('mcrypt')) {
  20.     /**
  21.      * Uses faster mcrypt library if available
  22.      */
  23.     require_once './libraries/mcrypt.lib.php';
  24. } else {
  25.     require_once './libraries/blowfish.php';
  26.     /**
  27.      * display warning in main.php
  28.      */
  29.     define('PMA_WARN_FOR_MCRYPT', 1);
  30. }
  31.  
  32.  
  33. /**
  34.  * Displays authentication form
  35.  *
  36.  * this function MUST exit/quit the application
  37.  *
  38.  * @uses    $GLOBALS['server']
  39.  * @uses    $GLOBALS['PHP_AUTH_USER']
  40.  * @uses    $GLOBALS['pma_auth_server']
  41.  * @uses    $GLOBALS['text_dir']
  42.  * @uses    $GLOBALS['pmaThemeImage']
  43.  * @uses    $GLOBALS['charset']
  44.  * @uses    $GLOBALS['target']
  45.  * @uses    $GLOBALS['db']
  46.  * @uses    $GLOBALS['table']
  47.  * @uses    $GLOBALS['PMA_errors']
  48.  * @uses    $GLOBALS['convcharset']
  49.  * @uses    $GLOBALS['lang']
  50.  * @uses    $GLOBALS['strWelcome']
  51.  * @uses    $GLOBALS['strSecretRequired']
  52.  * @uses    $GLOBALS['strError']
  53.  * @uses    $GLOBALS['strLogin']
  54.  * @uses    $GLOBALS['strLogServer']
  55.  * @uses    $GLOBALS['strLogUsername']
  56.  * @uses    $GLOBALS['strLogPassword']
  57.  * @uses    $GLOBALS['strServerChoice']
  58.  * @uses    $GLOBALS['strGo']
  59.  * @uses    $GLOBALS['strCookiesRequired']
  60.  * @uses    $GLOBALS['strPmaDocumentation']
  61.  * @uses    $GLOBALS['pmaThemeImage']
  62.  * @uses    $cfg['Servers']
  63.  * @uses    $cfg['LoginCookieRecall']
  64.  * @uses    $cfg['Lang']
  65.  * @uses    $cfg['Server']
  66.  * @uses    $cfg['ReplaceHelpImg']
  67.  * @uses    $cfg['blowfish_secret']
  68.  * @uses    $cfg['AllowArbitraryServer']
  69.  * @uses    $_COOKIE
  70.  * @uses    $_REQUEST['old_usr']
  71.  * @uses    PMA_sendHeaderLocation()
  72.  * @uses    PMA_select_language()
  73.  * @uses    PMA_select_server()
  74.  * @uses    PMA_VERSION
  75.  * @uses    file_exists()
  76.  * @uses    sprintf()
  77.  * @uses    count()
  78.  * @uses    htmlspecialchars()
  79.  * @uses    is_array()
  80.  * @global  string    the last connection error
  81.  *
  82.  * @access  public
  83.  */
  84. function PMA_auth()
  85. {
  86.     global $conn_error;
  87.  
  88.     /* Perform logout to custom URL */
  89.     if (! empty($_REQUEST['old_usr'])
  90.      && ! empty($GLOBALS['cfg']['Server']['LogoutURL'])) {
  91.         PMA_sendHeaderLocation($GLOBALS['cfg']['Server']['LogoutURL']);
  92.         exit;
  93.     }
  94.  
  95.     if ($GLOBALS['cfg']['LoginCookieRecall']) {
  96.         $default_user   = $GLOBALS['PHP_AUTH_USER'];
  97.         $default_server = $GLOBALS['pma_auth_server'];
  98.         $autocomplete   = '';
  99.     } else {
  100.         $default_user   = '';
  101.         $default_server = '';
  102.         // skip the IE autocomplete feature.
  103.         $autocomplete   = ' autocomplete="off"';
  104.     }
  105.  
  106.     $cell_align = ($GLOBALS['text_dir'] == 'ltr') ? 'left' : 'right';
  107.  
  108.     // Defines the charset to be used
  109.     header('Content-Type: text/html; charset=' . $GLOBALS['charset']);
  110.     // Defines the "item" image depending on text direction
  111.     $item_img = $GLOBALS['pmaThemeImage'] . 'item_' . $GLOBALS['text_dir'] . '.png';
  112.  
  113.     /* HTML header */
  114.     $page_title = 'phpMyAdmin ' . PMA_VERSION;
  115.     require './libraries/header_meta_style.inc.php';
  116.     ?>
  117. <script type="text/javascript">
  118. //<![CDATA[
  119. // show login form in top frame
  120. if (top != self) {
  121.     window.top.location.href=location;
  122. }
  123. //]]>
  124. </script>
  125. </head>
  126.  
  127. <body class="loginform">
  128.  
  129.     <?php
  130.     if (file_exists('./config.header.inc.php')) {
  131.           require './config.header.inc.php';
  132.     }
  133.     ?>
  134.  
  135. <div class="container">
  136. <a href="http://www.phpmyadmin.net" target="_blank" class="logo"><?php
  137.     $logo_image = $GLOBALS['pmaThemeImage'] . 'logo_right.png';
  138.     if (@file_exists($logo_image)) {
  139.         echo '<img src="' . $logo_image . '" id="imLogo" name="imLogo" alt="phpMyAdmin" border="0" />';
  140.     } else {
  141.         echo '<img name="imLogo" id="imLogo" src="' . $GLOBALS['pmaThemeImage'] . 'pma_logo.png' . '" '
  142.            . 'border="0" width="88" height="31" alt="phpMyAdmin" />';
  143.     }
  144.     ?></a>
  145. <h1>
  146.     <?php
  147.     echo sprintf($GLOBALS['strWelcome'],
  148.         '<bdo dir="ltr" xml:lang="en">' . $page_title . '</bdo>');
  149.     ?>
  150. </h1>
  151.     <?php
  152.  
  153.     // Show error message
  154.     if (! empty($conn_error)) {
  155.         echo '<div class="error"><h1>' . $GLOBALS['strError'] . '</h1>' . "\n";
  156.         echo $conn_error . '</div>' . "\n";
  157.     }
  158.  
  159.     // Displays the languages form
  160.     if (empty($GLOBALS['cfg']['Lang'])) {
  161.         require_once './libraries/display_select_lang.lib.php';
  162.         PMA_select_language(true);
  163.     }
  164.  
  165.     // Displays the warning message and the login form
  166.     if (empty($GLOBALS['cfg']['blowfish_secret'])) {
  167.         ?>
  168.         <div class="error"><h1><?php echo $GLOBALS['strError']; ?></h1>
  169.             <?php echo $GLOBALS['strSecretRequired']; ?>
  170.         </div>
  171.         <?php
  172.         echo '</div>' . "\n";
  173.         if (file_exists('./config.footer.inc.php')) {
  174.             require './config.footer.inc.php';
  175.         }
  176.         echo '</body></html>';
  177.         exit;
  178.     }
  179.     ?>
  180. <br />
  181. <!-- Login form -->
  182. <form method="post" action="index.php" name="login_form"<?php echo $autocomplete; ?> target="_top" class="login">
  183.     <fieldset>
  184.     <legend>
  185. <?php 
  186.     echo $GLOBALS['strLogin']; 
  187.     echo '<a href="./Documentation.html" target="documentation" ' .
  188.         'title="' . $GLOBALS['strPmaDocumentation'] . '">';
  189.     if ($GLOBALS['cfg']['ReplaceHelpImg']) {
  190.         echo '<img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 'b_help.png" width="11" height="11" alt="' . $GLOBALS['strPmaDocumentation'] . '" />';
  191.     } else {
  192.         echo '(*)';
  193.     }
  194.     echo '</a>';
  195. ?>
  196. </legend>
  197.  
  198. <?php if ($GLOBALS['cfg']['AllowArbitraryServer']) { ?>
  199.         <div class="item">
  200.             <label for="input_servername"><?php echo $GLOBALS['strLogServer']; ?></label>
  201.             <input type="text" name="pma_servername" id="input_servername" value="<?php echo htmlspecialchars($default_server); ?>" size="24" class="textfield" />
  202.         </div>
  203. <?php } ?>
  204.         <div class="item">
  205.             <label for="input_username"><?php echo $GLOBALS['strLogUsername']; ?></label>
  206.             <input type="text" name="pma_username" id="input_username" value="<?php echo htmlspecialchars($default_user); ?>" size="24" class="textfield" />
  207.         </div>
  208.         <div class="item">
  209.             <label for="input_password"><?php echo $GLOBALS['strLogPassword']; ?></label>
  210.             <input type="password" name="pma_password" id="input_password" value="" size="24" class="textfield" />
  211.         </div>
  212.     <?php
  213.     if (count($GLOBALS['cfg']['Servers']) > 1) {
  214.         ?>
  215.         <div class="item">
  216.             <label for="select_server"><?php echo $GLOBALS['strServerChoice']; ?>:</label>
  217.             <select name="server" id="select_server"
  218.         <?php
  219.         if ($GLOBALS['cfg']['AllowArbitraryServer']) {
  220.             echo ' onchange="document.forms[\'login_form\'].elements[\'pma_servername\'].value = \'\'" ';
  221.         }
  222.         echo '>';
  223.  
  224.         require_once './libraries/select_server.lib.php';
  225.         PMA_select_server(false, false);
  226.  
  227.         echo '</select></div>';
  228.     } else {
  229.         echo '    <input type="hidden" name="server" value="' . $GLOBALS['server'] . '" />';
  230.     } // end if (server choice)
  231.     ?>
  232.     </fieldset>
  233.     <fieldset class="tblFooters">
  234.         <input value="<?php echo $GLOBALS['strGo']; ?>" type="submit" />
  235.         <input type="hidden" name="lang" value="<?php echo $GLOBALS['lang']; ?>" />
  236.         <input type="hidden" name="convcharset" value="<?php echo htmlspecialchars($GLOBALS['convcharset'], ENT_QUOTES); ?>" />
  237.     <?php
  238.     if (!empty($GLOBALS['target'])) {
  239.         echo '            <input type="hidden" name="target" value="' . htmlspecialchars($GLOBALS['target']) . '" />' . "\n";
  240.     }
  241.     if (!empty($GLOBALS['db'])) {
  242.         echo '            <input type="hidden" name="db" value="' . htmlspecialchars($GLOBALS['db']) . '" />' . "\n";
  243.     }
  244.     if (!empty($GLOBALS['table'])) {
  245.         echo '            <input type="hidden" name="table" value="' . htmlspecialchars($GLOBALS['table']) . '" />' . "\n";
  246.     }
  247.     ?>
  248.     </fieldset>
  249. </form>
  250.     <?php
  251.     // show the "Cookies required" message only if cookies are disabled
  252.     // (we previously tried to set some cookies)
  253.     if (empty($_COOKIE)) {
  254.         echo '<div class="notice">' . $GLOBALS['strCookiesRequired'] . '</div>' . "\n";
  255.     }
  256.     if (! empty($GLOBALS['PMA_errors']) && is_array($GLOBALS['PMA_errors'])) {
  257.         foreach ($GLOBALS['PMA_errors'] as $error) {
  258.             echo '<div class="error">' . $error . '</div>' . "\n";
  259.         }
  260.     }
  261.     ?>
  262. </div>
  263. <script type="text/javascript">
  264. // <![CDATA[
  265. function PMA_focusInput()
  266. {
  267.     var input_username = document.getElementById('input_username');
  268.     var input_password = document.getElementById('input_password');
  269.     if (input_username.value == '') {
  270.         input_username.focus();
  271.     } else {
  272.         input_password.focus();
  273.     }
  274. }
  275.  
  276. window.setTimeout('PMA_focusInput()', 500);
  277. // ]]>
  278. </script>
  279. </body>
  280. </html>
  281.     <?php
  282.     if (file_exists('./config.footer.inc.php')) {
  283.          require './config.footer.inc.php';
  284.     }
  285.     exit;
  286. } // end of the 'PMA_auth()' function
  287.  
  288.  
  289. /**
  290.  * Gets advanced authentication settings
  291.  *
  292.  * this function DOES NOT check authentication - it just checks/provides
  293.  * authentication credentials required to connect to the MySQL server
  294.  * usally with PMA_DBI_connect()
  295.  *
  296.  * it returns false if there is missing something - which usally leads to
  297.  * PMA_auth() which displays login form
  298.  *
  299.  * it returns true if all seems ok which usally leads to PMA_auth_set_user()
  300.  *
  301.  * it directly switches to PMA_auth_fails() if user inactivity timout is reached
  302.  *
  303.  * @todo    AllowArbitraryServer on does not imply that the user wnats an
  304.  *          arbitrary server, or? so we should also check if this is filled and
  305.  *          not only if allowed
  306.  * @uses    $GLOBALS['PHP_AUTH_USER']
  307.  * @uses    $GLOBALS['PHP_AUTH_PW']
  308.  * @uses    $GLOBALS['no_activity']
  309.  * @uses    $GLOBALS['server']
  310.  * @uses    $GLOBALS['from_cookie']
  311.  * @uses    $GLOBALS['pma_auth_server']
  312.  * @uses    $cfg['blowfish_secret']
  313.  * @uses    $cfg['AllowArbitraryServer']
  314.  * @uses    $cfg['LoginCookieValidity']
  315.  * @uses    $cfg['Servers']
  316.  * @uses    $_REQUEST['old_usr'] from logout link
  317.  * @uses    $_REQUEST['pma_username'] from login form
  318.  * @uses    $_REQUEST['pma_password'] from login form
  319.  * @uses    $_REQUEST['pma_servername'] from login form
  320.  * @uses    $_COOKIE
  321.  * @uses    $_SESSION['last_access_time']
  322.  * @uses    PMA_removeCookie()
  323.  * @uses    PMA_blowfish_decrypt()
  324.  * @uses    PMA_auth_fails()
  325.  * @uses    time()
  326.  *
  327.  * @return  boolean   whether we get authentication settings or not
  328.  *
  329.  * @access  public
  330.  */
  331. function PMA_auth_check()
  332. {
  333.     // Initialization
  334.     /**
  335.      * @global $GLOBALS['pma_auth_server'] the user provided server to connect to
  336.      */
  337.     $GLOBALS['pma_auth_server'] = '';
  338.  
  339.     $GLOBALS['PHP_AUTH_USER'] = $GLOBALS['PHP_AUTH_PW'] = '';
  340.     $GLOBALS['from_cookie'] = false;
  341.  
  342.     // avoid an error in mcrypt
  343.     if (empty($GLOBALS['cfg']['blowfish_secret'])) {
  344.         return false;
  345.     }
  346.  
  347.     if (defined('PMA_CLEAR_COOKIES')) {
  348.         foreach($GLOBALS['cfg']['Servers'] as $key => $val) {
  349.             PMA_removeCookie('pmaPass-' . $key);
  350.             PMA_removeCookie('pmaServer-' . $key);
  351.             PMA_removeCookie('pmaUser-' . $key);
  352.         }
  353.         return false;
  354.     }
  355.  
  356.     if (! empty($_REQUEST['old_usr'])) {
  357.         // The user wants to be logged out 
  358.         // -> delete his choices that were stored in session 
  359.         session_destroy(); 
  360.         // -> delete password cookie(s)
  361.         if ($GLOBALS['cfg']['LoginCookieDeleteAll']) {
  362.             foreach($GLOBALS['cfg']['Servers'] as $key => $val) {
  363.                 PMA_removeCookie('pmaPass-' . $key);
  364.                 if (isset($_COOKIE['pmaPass-' . $key])) {
  365.                     unset($_COOKIE['pmaPass-' . $key]);
  366.                 }
  367.             }
  368.         } else {
  369.             PMA_removeCookie('pmaPass-' . $GLOBALS['server']);
  370.             if (isset($_COOKIE['pmaPass-' . $GLOBALS['server']])) {
  371.                 unset($_COOKIE['pmaPass-' . $GLOBALS['server']]);
  372.             }
  373.         }
  374.     }
  375.  
  376.     if (! empty($_REQUEST['pma_username'])) {
  377.         // The user just logged in
  378.         $GLOBALS['PHP_AUTH_USER'] = $_REQUEST['pma_username'];
  379.         $GLOBALS['PHP_AUTH_PW']   = empty($_REQUEST['pma_password']) ? '' : $_REQUEST['pma_password'];
  380.         if ($GLOBALS['cfg']['AllowArbitraryServer'] && isset($_REQUEST['pma_servername'])) {
  381.             $GLOBALS['pma_auth_server'] = $_REQUEST['pma_servername'];
  382.         }
  383.         return true;
  384.     }
  385.  
  386.     // At the end, try to set the $GLOBALS['PHP_AUTH_USER']
  387.     // and $GLOBALS['PHP_AUTH_PW'] variables from cookies
  388.  
  389.     // servername
  390.     if ($GLOBALS['cfg']['AllowArbitraryServer']
  391.      && ! empty($_COOKIE['pmaServer-' . $GLOBALS['server']])) {
  392.         $GLOBALS['pma_auth_server'] = $_COOKIE['pmaServer-' . $GLOBALS['server']];
  393.     }
  394.  
  395.     // username
  396.     if (empty($_COOKIE['pmaUser-' . $GLOBALS['server']])) {
  397.         return false;
  398.     }
  399.  
  400.     $GLOBALS['PHP_AUTH_USER'] = PMA_blowfish_decrypt(
  401.         $_COOKIE['pmaUser-' . $GLOBALS['server']],
  402.         $GLOBALS['cfg']['blowfish_secret']);
  403.  
  404.     // user was never logged in since session start
  405.     if (empty($_SESSION['last_access_time'])) {
  406.         return false;
  407.     }
  408.  
  409.     // User inactive too long
  410.     if ($_SESSION['last_access_time'] < time() - $GLOBALS['cfg']['LoginCookieValidity']) {
  411.         $GLOBALS['no_activity'] = true;
  412.         PMA_auth_fails();
  413.         exit;
  414.     }
  415.  
  416.     // password
  417.     if (empty($_COOKIE['pmaPass-' . $GLOBALS['server']])) {
  418.         return false;
  419.     }
  420.  
  421.     $GLOBALS['PHP_AUTH_PW'] = PMA_blowfish_decrypt(
  422.         $_COOKIE['pmaPass-' . $GLOBALS['server']],
  423.         $GLOBALS['cfg']['blowfish_secret'] /* . $_SESSION['last_access_time'] */);
  424.  
  425.     if ($GLOBALS['PHP_AUTH_PW'] == "\xff(blank)") {
  426.         $GLOBALS['PHP_AUTH_PW'] = '';
  427.     }
  428.  
  429.     $GLOBALS['from_cookie'] = true;
  430.  
  431.     return true;
  432. } // end of the 'PMA_auth_check()' function
  433.  
  434.  
  435. /**
  436.  * Set the user and password after last checkings if required
  437.  *
  438.  * @uses    $GLOBALS['PHP_AUTH_USER']
  439.  * @uses    $GLOBALS['PHP_AUTH_PW']
  440.  * @uses    $GLOBALS['server']
  441.  * @uses    $GLOBALS['from_cookie']
  442.  * @uses    $GLOBALS['pma_auth_server']
  443.  * @uses    $cfg['Server']
  444.  * @uses    $cfg['AllowArbitraryServer']
  445.  * @uses    $cfg['blowfish_secret']
  446.  * @uses    $cfg['LoginCookieStore']
  447.  * @uses    $cfg['PmaAbsoluteUri']
  448.  * @uses    $_SESSION['last_access_time']
  449.  * @uses    PMA_COMING_FROM_COOKIE_LOGIN
  450.  * @uses    PMA_setCookie()
  451.  * @uses    PMA_blowfish_encrypt()
  452.  * @uses    PMA_removeCookie()
  453.  * @uses    PMA_sendHeaderLocation()
  454.  * @uses    time()
  455.  * @uses    define()
  456.  * @return  boolean   always true
  457.  *
  458.  * @access  public
  459.  */
  460. function PMA_auth_set_user()
  461. {
  462.     global $cfg;
  463.  
  464.     // Ensures valid authentication mode, 'only_db', bookmark database and
  465.     // table names and relation table name are used
  466.     if ($cfg['Server']['user'] != $GLOBALS['PHP_AUTH_USER']) {
  467.         foreach ($cfg['Servers'] as $idx => $current) {
  468.             if ($current['host'] == $cfg['Server']['host']
  469.              && $current['port'] == $cfg['Server']['port']
  470.              && $current['socket'] == $cfg['Server']['socket']
  471.              && $current['ssl'] == $cfg['Server']['ssl']
  472.              && $current['connect_type'] == $cfg['Server']['connect_type']
  473.              && $current['user'] == $GLOBALS['PHP_AUTH_USER']) {
  474.                 $GLOBALS['server'] = $idx;
  475.                 $cfg['Server']     = $current;
  476.                 break;
  477.             }
  478.         } // end foreach
  479.     } // end if
  480.  
  481.     $pma_server_changed = false;
  482.     if ($GLOBALS['cfg']['AllowArbitraryServer']
  483.      && ! empty($GLOBALS['pma_auth_server'])
  484.      && $cfg['Server']['host'] != $GLOBALS['pma_auth_server']) {
  485.         $cfg['Server']['host'] = $GLOBALS['pma_auth_server'];
  486.         $pma_server_changed = true;
  487.     }
  488.     $cfg['Server']['user']     = $GLOBALS['PHP_AUTH_USER'];
  489.     $cfg['Server']['password'] = $GLOBALS['PHP_AUTH_PW'];
  490.  
  491.     $_SESSION['last_access_time'] = time();
  492.  
  493.     // Name and password cookies needs to be refreshed each time
  494.     // Duration = one month for username
  495.     PMA_setCookie('pmaUser-' . $GLOBALS['server'],
  496.         PMA_blowfish_encrypt($cfg['Server']['user'],
  497.             $GLOBALS['cfg']['blowfish_secret']));
  498.  
  499.     // Duration = as configured
  500.     PMA_setCookie('pmaPass-' . $GLOBALS['server'],
  501.         PMA_blowfish_encrypt(!empty($cfg['Server']['password']) ? $cfg['Server']['password'] : "\xff(blank)",
  502.             $GLOBALS['cfg']['blowfish_secret'] /* . $_SESSION['last_access_time'] */),
  503.         null,
  504.         $GLOBALS['cfg']['LoginCookieStore']);
  505.  
  506.     // Set server cookies if required (once per session) and, in this case, force
  507.     // reload to ensure the client accepts cookies
  508.     if (! $GLOBALS['from_cookie']) {
  509.         if ($GLOBALS['cfg']['AllowArbitraryServer']) {
  510.             if (! empty($GLOBALS['pma_auth_server'])) {
  511.                 // Duration = one month for serverrname
  512.                 PMA_setCookie('pmaServer-' . $GLOBALS['server'], $cfg['Server']['host']);
  513.             } else {
  514.                 // Delete servername cookie
  515.                 PMA_removeCookie('pmaServer-' . $GLOBALS['server']);
  516.             }
  517.         }
  518.  
  519.         // URL where to go:
  520.         $redirect_url = $cfg['PmaAbsoluteUri'] . 'index.php';
  521.  
  522.         // any parameters to pass?
  523.         $url_params = array();
  524.         if (strlen($GLOBALS['db'])) {
  525.             $url_params['db'] = $GLOBALS['db'];
  526.         }
  527.         if (strlen($GLOBALS['table'])) {
  528.             $url_params['table'] = $GLOBALS['table'];
  529.         }
  530.         // Language change from the login panel needs to be remembered
  531.         if (! empty($GLOBALS['lang'])) {
  532.             $url_params['lang'] = $GLOBALS['lang'];
  533.         }
  534.         // any target to pass?
  535.         if (! empty($GLOBALS['target']) && $GLOBALS['target'] != 'index.php') {
  536.             $url_params['target'] = $GLOBALS['target'];
  537.         }
  538.  
  539.         /**
  540.          * whether we come from a fresh cookie login
  541.          */
  542.         define('PMA_COMING_FROM_COOKIE_LOGIN', true);
  543.         PMA_sendHeaderLocation($redirect_url . PMA_generate_common_url($url_params, '&'));
  544.         exit();
  545.     } // end if
  546.  
  547.     return true;
  548. } // end of the 'PMA_auth_set_user()' function
  549.  
  550.  
  551. /**
  552.  * User is not allowed to login to MySQL -> authentication failed
  553.  *
  554.  * prepares error message and switches to PMA_auth() which display the error
  555.  * and the login form
  556.  *
  557.  * this function MUST exit/quit the application,
  558.  * currently doen by call to PMA_auth()
  559.  *
  560.  * @todo    $php_errormsg is invalid here!? it will never be set in this scope
  561.  * @uses    $GLOBALS['server']
  562.  * @uses    $GLOBALS['allowDeny_forbidden']
  563.  * @uses    $GLOBALS['strAccessDenied']
  564.  * @uses    $GLOBALS['strNoActivity']
  565.  * @uses    $GLOBALS['strCannotLogin']
  566.  * @uses    $GLOBALS['no_activity']
  567.  * @uses    $cfg['LoginCookieValidity']
  568.  * @uses    PMA_removeCookie()
  569.  * @uses    PMA_getenv()
  570.  * @uses    PMA_DBI_getError()
  571.  * @uses    PMA_sanitize()
  572.  * @uses    PMA_auth()
  573.  * @uses    sprintf()
  574.  * @uses    basename()
  575.  * @access  public
  576.  */
  577. function PMA_auth_fails()
  578. {
  579.     global $conn_error;
  580.  
  581.     // Deletes password cookie and displays the login form
  582.     PMA_removeCookie('pmaPass-' . $GLOBALS['server']);
  583.  
  584.     if (! empty($GLOBALS['allowDeny_forbidden'])) {
  585.         $conn_error = $GLOBALS['strAccessDenied'];
  586.     } elseif (! empty($GLOBALS['no_activity'])) {
  587.         $conn_error = sprintf($GLOBALS['strNoActivity'], $GLOBALS['cfg']['LoginCookieValidity']);
  588.         // Remember where we got timeout to return on same place
  589.         if (PMA_getenv('SCRIPT_NAME')) {
  590.             $GLOBALS['target'] = basename(PMA_getenv('SCRIPT_NAME'));
  591.         }
  592.     } elseif (PMA_DBI_getError()) {
  593.         $conn_error = PMA_sanitize(PMA_DBI_getError());
  594.     } elseif (isset($php_errormsg)) {
  595.         $conn_error = $php_errormsg;
  596.     } else {
  597.         $conn_error = $GLOBALS['strCannotLogin'];
  598.     }
  599.  
  600.     PMA_auth();
  601. } // end of the 'PMA_auth_fails()' function
  602.  
  603. ?>
  604.